package com.boat.framework.common.monitor.event;

import cn.hutool.core.util.StrUtil;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * 事务回滚事件
 * 
 * @author 周江
 *
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class TrxRollbacked extends BaseMonitorEvent {
	/**
	 * 错误类型
	 */
	private String exceptionType;
	/**
	 * 异常消息
	 */
	private String exceptionMsg;
	/**
	 * 备注
	 */
	private String remark;

	public TrxRollbacked() {
		super();
	}

	public TrxRollbacked(Throwable ex) {
		super();
		String exceptionType = ex.getCause() != null ? ex.getCause().getClass().getSimpleName() : ex.getClass().getSimpleName();
		String exceptionMsg = ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage();
		String name = exceptionType+ "_"+StrUtil.maxLength(exceptionMsg, 15);
		
		setName(name);
		setExceptionType(exceptionType);
		setExceptionMsg(exceptionMsg);
		setRemark("发生数据库事务回滚");
	}
}